package com.hw.spark.listener;

import org.apache.spark.scheduler.SparkListener;
import org.apache.spark.scheduler.SparkListenerApplicationEnd;
import org.apache.spark.scheduler.SparkListenerApplicationStart;
import org.apache.spark.scheduler.SparkListenerJobEnd;
import org.apache.spark.scheduler.SparkListenerJobStart;
import org.apache.spark.scheduler.SparkListenerTaskEnd;
import org.apache.spark.scheduler.SparkListenerTaskStart;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SparkSQLListener extends SparkListener {

	private static final Logger log = LoggerFactory.getLogger(SparkSQLListener.class);

	@Override
	public void onTaskStart(SparkListenerTaskStart taskStart) {
		log.info("任务开始:[" + taskStart.stageId() + ":" + taskStart.toString() + "]");
	}

	@Override
	public void onTaskEnd(SparkListenerTaskEnd taskEnd) {
		log.info("任务结束:[" + taskEnd.stageId() + ":" + taskEnd.toString() + "]");
	}

	@Override
	public void onJobStart(SparkListenerJobStart jobStart) {
		log.info("工作开始:[" + jobStart.jobId() + ":" + jobStart.toString() + "]");
	}

	@Override
	public void onJobEnd(SparkListenerJobEnd jobEnd) {
		log.info("工作结束:[" + jobEnd.jobId() + ":" + jobEnd.toString() + "]");
	}

	@Override
	public void onApplicationStart(SparkListenerApplicationStart applicationStart) {
		log.info("应用开始:[" + applicationStart.appId() + ":" + applicationStart.appName() + "]");
	}

	@Override
	public void onApplicationEnd(SparkListenerApplicationEnd applicationEnd) {
		log.info("应用结束:[时间:" + applicationEnd.time() + "]");
	}
}